"use strict";
let morePlayListButton = document.querySelector(".recommendAlbums .recommendAlbumsTitle .morePlayList");
morePlayListButton.addEventListener("click", (event) => {
    utils.navigateTo("#songMenu")
})

let navigateColumn = () => {
    let dailyRecommend = document.querySelector("#dailyRecommend");
    let personalFM = document.querySelector("#personalFM");
    let songMenu = document.querySelector("#songMenu");
    let rank = document.querySelector("#rank");

    changeCalendarIconByDate(dailyRecommend)
}



let carouselResources = () => {
    //  爬取出来的轮播图资源 先不对api 这个工作放到后期去做
    let imgData = [
        "http://p1.music.126.net/olLPEn83o2ESZqOXfIIWjQ==/109951168042860022.jpg",
        "http://p1.music.126.net/a4e00RNX3Uvuu0kAIC6qrQ==/109951168042366365.jpg",
        "http://p1.music.126.net/_YmNO0d0R9wgCslHDMv12w==/109951168042521369.jpg",
        "http://p1.music.126.net/_2AE1J1cdii1dNfko2as0g==/109951168042385763.jpg",
        "http://p1.music.126.net/UBLEVJK0cwyfI3RxXvVsOg==/109951168045185619.jpg",
        "http://p1.music.126.net/LEGS-zhz1h-aTN4PcCph9A==/109951168044476735.jpg",
        "http://p1.music.126.net/fQx0BmL6gQV6HBWqfHLBsw==/109951168042539574.jpg",
    ]
    utils.carousel(imgData);
}

//  获取推荐歌单
let recommendAlbums = () => {
    let recommendAlbumContent = document.querySelector(".recommendAlbumsContent");
    let playList = [
        {
            albumId: 626186882,
            picUrl: "https://p2.music.126.net/QcPJfzds8ejF1FPgBaXMTw==/109951163128461676.jpg",
            albumName: "古典清香 I 我的茶馆里住着巴赫与肖邦",
        }, {
            albumId: 1982066521,
            picUrl: "https://p2.music.126.net/kZb9DO4vykqiYEx0HHx86w==/109951163065542645.jpg",
            albumName: "假如能回到过去，你想做什么",
        }, {
            albumId: 2098892084,
            picUrl: "https://p2.music.126.net/_Ej6TahANI-aqsJCTf7uCA==/109951163240060789.jpg",
            albumName: "“温柔点吧，这个世界已经够浮躁的了”",
        }, {
            albumId: 2312165875,
            picUrl: "https://p2.music.126.net/Cl0-NpZ0ESTDjJ1HmZ33KA==/109951163460576279.jpg",
            albumName: "100首华语民谣，因为懂得才有共鸣",
        }, {
            albumId: 610040691,
            picUrl: "https://p2.music.126.net/FoF5_ROj-jU37263LhInsw==/109951163203287436.jpg",
            albumName: "听首老歌 回味永不褪色的华语经典",
        }, {
            albumId: 626186882,
            picUrl: "https://p1.music.126.net/VULJoL3yPHk237z7kM8Yrg==/18802748348431366.jpg",
            albumName: "响指系」令人着迷的响指节奏♬",
        },
    ]
    playList.forEach((item) => {
        recommendAlbumContent.innerHTML += `
            <li class="recommendAlbumsList" data-album-id="${item.albumId}">
                <a href="#musicPlaylist">
                    <img src="${item.picUrl}?param=200y200"/>
                    <p>${item.albumName}</p>
                </a>
            <li/>`
    })
    let recommendAlbumsList = document.querySelectorAll(".recommendAlbumsList");
    //  加载歌单信息，给歌单赋予点击跳转事件
    utils.musicPlayListLoader(recommendAlbumsList)
}

let changeCalendarIconByDate = (obj) => {
    let date = new Date();
    let now = date.getDate();
    switch (now) {
        case 1:
            modify("&#xe600;");
            break;
        case 2:
            modify("&#xe601;");
            break;
        case 3:
            modify("&#xe603;");
            break;
        case 4:
            modify("&#xe602;");
            break;
        case 5:
            modify("&#xe604;");
            break;
        case 6:
            modify("&#xe60d;");
            break;
        case 7:
            modify("&#xe605;");
            break;
        case 8:
            modify("&#xe606;");
            break;
        case 9:
            modify("&#xe608;");
            break;
        case 10:
            modify("&#xe60a;");
            break;
        case 11:
            modify("&#xe607;");
            break;
        case 12:
            modify("&#xe609;");
            break;
        case 13:
            modify("&#xe60b;");
            break;
        case 14:
            modify("&#xe60c;");
            break;
        case 15:
            modify("&#xe60e;");
            break;
        case 16:
            modify("&#xe610;");
            break;
        case 17:
            modify("&#xe60f;");
            break;
        case 18:
            modify("&#xe612;");
            break;
        case 19:
            modify("&#xe613;");
            break;
        case 20:
            modify("&#xe615;");
            break;
        case 21:
            modify("&#xe614;");
            break;
        case 22:
            modify("&#xe617;");
            break;
        case 23:
            modify("&#xe619;");
            break;
        case 24:
            modify("&#xe616;");
            break;
        case 25:
            modify("&#xe618;")
            break;
        case 26:
            modify("&#xe61b;")
            break;
        case 27:
            modify("&#xe61a;")
            break;
        case 28:
            modify("&#xe61d;")
            break;
        case 29:
            modify("&#xe61c;")
            break;
        case 30:
            modify("&#xe61f;")
            break;
        case 31:
            modify("&#xe61e;")
            break;
        default:
            break;
    }
    function modify(icon) {
        obj.innerHTML =  `
            <a href="#dailyRecommend">
                <i>${icon}</i>
                <p>每日推荐<p/>
            <a/>
        `
    }
}

//推荐MV
async function recommendMV() {
    let recommendMVContent = document.querySelector("#recommendMVContent");
    let result = await utils.request("get", "/personalized/mv");
    if (result.code == 200) {
        result = result.result;
        result.forEach((element) => {
            let name = element.name;
            let picUrl = element.picUrl;
            let id = element.id;
            let playCount = element.playCount;
            recommendMVContent.innerHTML += `<li class="recommendMVlist" data-id="${id}">
            <img src="${picUrl}?param=250y150"></img>
            <p>${name}</p>
            <i>&#xe660;</i>
            <p class="recommendMVPlayCount">&#xe660;  ${playCount}</p>
          </li>`;
        });
    }
}


//  函数调用
navigateColumn()
carouselResources()
recommendAlbums()
recommendMV()